from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from modal import App, mount
from modal import Image, Secret, asgi_app

# from _mem0 import router as mem0_router
from _multion import router as multion_router
from basic import conversation_created as basic_conversation_created_router
from oauth import conversation_created as oauth_conversation_created_router
from zapier import conversation_created as zapier_conversation_created_router
from chatgpt import main as chatgpt_router
from subscription import main as subscription_router
from notifications import hey_omi
from notifications.mentor import main as omi_mentor

# from ahda import client as ahda_realtime_transcription_router
# from advanced import openglass as advanced_openglass_router

# ************* @DEPRECATED **************
# REALTIME plugins are not ready yet: (After various attempts, we found the following:
# 1. Super expensive to maintain, running a llm or certain logic every 3 seconds for 10 hours a day is not cheap.
# 2. There has to be a better way to trigger those plugins, current way is not efficient.
# 3. Didn't find killer use cases.
# from advanced import realtime as advanced_realtime_router
# from basic import realtime as basic_realtime_router
from basic import mentor as basic_realtime_mentor_router

# ****************************************

app = FastAPI()
app.mount("/templates/static", StaticFiles(directory="templates/static"), name="templates_static")

modal_app = App(
    name='plugins',
    secrets=[Secret.from_dotenv('.env')],
    mounts=[mount.Mount.from_local_dir('templates/', remote_path='templates/')],
)


@modal_app.function(
    image=(
        Image.debian_slim()
        # .apt_install('libgl1-mesa-glx', 'libglib2.0-0')
        .pip_install_from_requirements('requirements.txt')
    ),
    keep_warm=1,  # need 7 for 1rps
    memory=(128, 512),
    cpu=1,
    allow_concurrent_inputs=10,
)
@asgi_app()
def api():
    return app


app.include_router(basic_conversation_created_router.router)
app.include_router(oauth_conversation_created_router.router)
app.include_router(zapier_conversation_created_router.router)
# app.include_router(ahda_realtime_transcription_router.router)

app.include_router(basic_realtime_mentor_router.router)
# app.include_router(basic_realtime_router.router)
# app.include_router(advanced_realtime_router.router)
# app.include_router(advanced_openglass_router.router)

# ***********************************************
# ************ EXTERNAL INTEGRATIONS ************
# ***********************************************

# Multion
app.include_router(multion_router.router)

# ChatGPT
app.include_router(chatgpt_router.router)

# Subscription
app.include_router(subscription_router.router)

# Notifications
app.include_router(hey_omi.router)
app.include_router(omi_mentor.router)
